<?php
/**
 * Created by PhpStorm.
 * User: yangjiaming
 * Date: 2018/2/4
 * Time: 22:01
 */

namespace Halo;


class View
{
    protected $variables = array();
    protected $_controller;
    protected $_action;
    public function __construct($controller, $action)
    {
        $this->_controller = $controller;
        $this->_action = $action;
    }
    public function display($tpl)
    {
        extract($this->variables);
        //$defaultHeader = APP_PATH . 'application/views/header.php';
        //$defaultFooter = APP_PATH . 'application/views/footer.php';

        //$controllerHeader = APP_PATH . 'application/views/' . $this->_controller . '/header.php';
        //$controllerFooter = APP_PATH . 'application/views/' . $this->_controller . '/footer.php';
        $tpl = $tpl?$tpl:$this->_action;
        $controllerLayout = APPLICATION_PATH . '/application/views/' . $this->_controller . '/' . $tpl . '.html';

        // 页头文件
        /*if (file_exists($controllerHeader)) {
            include ($controllerHeader);
        } else {
            include ($defaultHeader);
        }*/

        include ($controllerLayout);

        // 页脚文件
        /*if (file_exists($controllerFooter)) {
            include ($controllerFooter);
        } else {
            include ($defaultFooter);
        }*/
    }
    public function assign($name, $value)
    {
        $this->variables[$name] = $value;
    }
}